<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../common/vue2/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <p>{{message}}</p>
      <button @click="change">点击</button>
      <div v-bind:class="{ active: isActive }">状态</div>
      <div v-bind:class="classObject">状态2</div>
      <div v-bind:class="[activeClass,errorClass]">状态3</div>
    </div>

    <script type="text/javascript">
      var app = new Vue({
        el: "#app",
        data: {
          message: "Hello Vue!",
          isActive: true,
          error:true,
          activeClass:'active',
          errorClass:'text-danger'
         
        },
        computed:{
            classObject:function(){
                return{
                    active:this.isActive,
                    'text-danger':this.error
                }
            }

        },
        methods: {
            change(){
                this.isActive = !this.isActive
                this.error = !this.error
                this.activeClass = null
                this.errorClass = null
                
            }
        },
      });
    </script>
  </body>
  <style scoped>
    .active {
      color: #42b983;
    }
    .text-danger{
        background-color: red;
    }
  </style>
</html>
